<?php

namespace App\Domain\ApplicationCenter\Dao;

use App\Domain\ApplicationCenter\Models\ApplicationCenterModel;

class ApplicationCenterDao
{


    public function findByName($name)
    {
        return ApplicationCenterModel::where('name', $name)->first();
    }

    public function findById($id)
    {
        return ApplicationCenterModel::where('id', $id)->first();
    }

    /**
     * 创建app
     * @param $params
     * @return ApplicationCenterModel
     */
    public function create($params)
    {
        $params = array_filter_null($params);
        return ApplicationCenterModel::create($params);
    }

    /**
     * 修改app
     * @param ApplicationCenterModel $model
     * @param $params
     * @return ApplicationCenterModel
     */
    public function update(ApplicationCenterModel $model, $params)
    {
        $params = array_filter_null($params);
        $model->fill($params)->save();
        return $model;
    }

    //删除app
    public function del($id)
    {
        return ApplicationCenterModel::where('id', $id)->update(['state' => '0']);
    }
}
